﻿// <copyright file="HomeController.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the main controller</summary>

namespace Sqwarea.Web.Controllers
{
    using System;
    using System.Web.Mvc;
    using Sqwarea.GameLogic.TopList;
    using Sqwarea.Persistence;
    using Sqwarea.Web.Misc;

    /// <summary>
    /// Main controlller
    /// </summary>
    [HandleError]
    public class HomeController : SecuredController
    {
        /// <summary>
        /// Top List Provider (to display best kings)
        /// </summary>
        private readonly ITopListProvider _topListProvider;

        /// <summary>
        /// Initializes a new instance of the HomeController class
        /// </summary>
        /// <param name="userProvider">The user provider</param>
        /// <param name="topListProvider">The Top List provider</param>
        public HomeController(IUserProvider userProvider, ITopListProvider topListProvider)
            : base(userProvider)
        {
            if (null == topListProvider)
            {
                throw new ArgumentNullException("topListProvider", "HomeController");
            }

            _topListProvider = topListProvider;
        }

        /// <summary>
        /// Action returning the main view
        /// </summary>
        /// <returns>The main view</returns>
        [Unrestricted]
        public ActionResult Index()
        {
            ViewData["User"] = User;

            ViewData["BestKings"] = _topListProvider.GetBestKings();

            ViewData["LastRegisteredUsers"] = null; // Not avail. yet.

            return View();
        }
    }
}
